[.NET Performance Counter] "System.ComponentModel.Win32Exception: Access is denied" is thrown when c

Posted by Ricky on Stack Overflow See other posts from Stack Overflow or by Ricky
Published on 2010-03-29T08:51:00Z Indexed on 2010/03/29 8:53 UTC
Read the original article Hit count: 795

Filed under:
|

Hi guys:

Calling PerformanceCounterCategory.Create() below on my machine thorws out this exception:

System.ComponentModel.Win32Exception: Access is denied

Do you know what's the issue about it?

Thank you!

        if (!PerformanceCounterCategory.Exists("MyCategory"))
        {
            CounterCreationDataCollection counters = new CounterCreationDataCollection();

            CounterCreationData avgDurationBase = new CounterCreationData();
            avgDurationBase.CounterName = "average time per operation base";
            avgDurationBase.CounterHelp = "Average duration per operation execution base";
            avgDurationBase.CounterType = PerformanceCounterType.AverageBase;
            counters.Add(avgDurationBase);


            // create new category with the counters above
            PerformanceCounterCategory.Create("MyCategory",
                "Sample category for Codeproject", PerformanceCounterCategoryType.SingleInstance, counters);
        }

© Stack Overflow or respective owner

Related posts about .NET

Related posts about performancecounter